<%--
  Created by IntelliJ IDEA.
  User: zk
  Date: 2017/11/9
  Time: 10:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<sys:message content="${message}"></sys:message>

<blockquote class="layui-elem-quote">${title}</blockquote>
    <form:form id="searchForm" class="layui-form"  action="${ctx}/sys/dict/list" method="post" modelAttribute="dict">
        <input type="hidden" id="page" name="page" value="${dict.page}" >
        <input type="hidden" id="rows" name="rows" value="${dict.limit}">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">描述</label>
                <div class="layui-input-inline" style="width: 150px;">
                    <form:input path="description" cssClass="layui-input" placeholder="请输入描述"></form:input>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-inline">
                    <select name="type" lay-search>
                        <option value="">请选择类型</option>
                        <c:forEach items="${typeList}" var="type">
                            <option value="${type}">${type}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <button class="layui-btn " lay-submit=""><i class="layui-icon">&#xe615;</i>查询</button>
            </div>
            <div class="layui-inline" style="float: right">
                <a href="${ctx}/sys/dict/form" class="layui-btn"><i class="layui-icon">&#xe608;</i>新增字典</a>
            </div>
        </div>

    </form:form>

<br>

<table class="layui-table" id="dictList" lay-filter="dictList" >
</table>
<div id="page" style="float: right"></div>
<sys:page baseUrl="${ctx}/sys/dict/list" page="${page}"/>

<script>
    $(function(){
        var table = layui.table,form = layui.form;
        form.render();
        table.render({
            elem: '#dictList' //指定原始表格元素选择器（推荐id选择器）
            ,cols: [[
                {field: 'label', title: '键名',edit:'text',align:'center'},
                {field: 'value', title: '键值',edit:'text',align:'center'},
                {field: 'type', title: '类型',edit:'text',align:'center'},
                {field: 'sort', title: '排序',edit:'text',align:'center'},
                {field: 'description', title: '描述',edit:'text'},
                {title: '操作',toolbar: '#operateCol',align:'center'}]] //设置表头
            ,data:${fns:toJson(page.list)}
        });

        table.on('tool(dictList)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if(layEvent === 'edit'){ //编辑权限
                pjaxReq(ctx+'/sys/dict/form?id='+data.id);
            } else if(layEvent === 'del'){ //删除
                delCustom('确定删除该字典吗？',ctx+'/sys/dict/delete?id='+data.id);
            } else if(layEvent === 'save'){ //保存
                ajaxPost('${ctx}/sys/dict/saveResp',data,function(respData){
                    layui.layer.msg(respData,{anim: 1});
                });
                //同步更新缓存对应的值
//            obj.update({
//                username: '123'
//                ,title: 'xxx'
//            });
            }
        });
    });

</script>

<script type="text/html" id="operateCol">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit" data-pjax>编辑</a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="save">保存</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" data-pjax>删除</a>

</script>